<template>
  <div class="icons">
    <ul>
      <swiper :options="swiperOptions">
        <swiper-slide v-for="(page,index) of pages" :key="index">
          <li v-for="item of page" :key="item.id">
            <img :src="item.imgUrl" alt />
            <span>{{item.desc}}</span>
          </li>
        </swiper-slide>
      </swiper>
    </ul>
  </div>
</template>
<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  data() {
    return {
      swiperOptions: {
        autoplay: false
      }
    }
  },
  computed: {
    pages() {
      const pages = []
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>
<style lang='stylus' scoped>
@import '~styles/mixins.styl';

.icons {
  li {
    float: left;
    width: 25%;
    text-align: center;
    padding-top: 0.1rem;

    img {
      display: block;
      width: 1.1rem;
      height: 1.1rem;
      margin: 0 auto;
    }

    span {
      display: block;
      margin-top: 0.1rem;
      color: #212121;
      font-size: 0.28rem;
      ellipsis();
    }
  }
}
</style>
